package com.tangding.shiro.realm;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.tangding.common.exception.GException;
import com.tangding.common.logx.LogHelp;
import com.tangding.service.entity.role.Role;
import com.tangding.service.entity.user.User;
import com.tangding.service.role.RoleService;
import com.tangding.service.user.UserService;

/**
 * @description 
 *
 * @author Ranger
 * @version 2017年11月9日_上午10:54:46
 *
 */
@Component
public class UserRealmHelper {
	
	static UserService userService;
	
	@Autowired
	public void setUserService(UserService userService) {
		UserRealmHelper.userService = userService;
	}

	static RoleService roleService;
	
	@Autowired
	public void setRoleService(RoleService roleService) {
		UserRealmHelper.roleService = roleService;
	}

	
	public static User findUsersByUid(String username) {
		try {
			User user = userService.findUsersByUid(username);
			return user;
		} catch (GException e) {
			LogHelp.doLogAppErr(e);
			return null;
		}
	}
	
	public static List<Role> getRoles(List<Integer> ids) {
		try {
			List<Role> roles = roleService.getRoles(ids);
			return roles;
		} catch (GException e) {
			LogHelp.doLogAppErr(e);
			return null;
		}
	}
}
